package com.victor.service.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.victor.dao.MyselfDao;
import com.victor.entity.CardPhoto;
import com.victor.entity.JMInfo;
import com.victor.entity.JMPhoto;
import com.victor.entity.User;
import com.victor.entity.UserFeedback;
import com.victor.entity.UserFeedbackClass;
import com.victor.entity.UserFeedbackPhoto;
import com.victor.service.MyselfService;
import com.victor.utils.Msg;

@Service
public class MyselfServiceImpl implements MyselfService{

	@Autowired
	private MyselfDao myselfDao;
	
	/**
	 * 	修改用户的信息
	 */
	@Override
	public boolean updateUser(User user) {
		int i =  myselfDao.updateUser(user);
		if (i>0) {
			return true;
		}
		return false;
	}

	/**
	 * 	提交加盟信息
	 */
	@Override
	public boolean submitJMInfo(JMInfo jmInfo) {
		return myselfDao.submitJMInfo(jmInfo);
	}
	
	/**
	 *	提交加盟营业执照，身份证，经营许可证，环境等相关照片
	 */
	@Override
	public boolean submitPhoto(JMPhoto photos) {
		return myselfDao.submitPhoto(photos);	
	}

	/**
	 * 	根据id获取用户原密码
	 */
	@Override
	public User getUserById(Integer id) {
		return myselfDao.getUserById(id);
	}

	/**
	 * 提交反馈信息
	 */
	@Override
	public boolean addfeedback(UserFeedback userFeedback) {
		return myselfDao.addfeedback(userFeedback);
	}
	//提交反馈图片
	@Override
	public boolean addfeedbackPhoto(UserFeedbackPhoto userFeedbackPhoto) {
		return myselfDao.addfeedbackPhoto(userFeedbackPhoto);
	}

	/**
	 * 后台添加反馈类型
	 */
	@Override
	public boolean addBackClass(UserFeedbackClass userFeedbackClass) {
		return myselfDao.addBackClass(userFeedbackClass);
	}

	/**
	 * 后台删除反馈类型,信息及图片
	 */
	@Override
	public boolean delBackClassById(Integer id) {
		//通过id删除要反馈的类型
		boolean b = myselfDao.delBackClassById(id);
		if (!b) {
			return false;
		}
		//通过id查询所有反馈信息表的id
		List<Integer> list  = myselfDao.selIdByClassId(id+"");
		//通过类型id删除所有反馈信息
		boolean c = myselfDao.delBackByClassId(id);
		if (!c) {
			return false;
		}
		//通过类型id删除所有反馈信息图片
		for (int i = 0; i < list.size(); i++) {
			boolean o = myselfDao.delPhotoByClassId(list.get(i)+"");
			if (!o) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 根据传入UserFeedback字段，查询列表
	 */
	@Override
	public List<UserFeedback> selectBack(UserFeedback userFeedback) {
		return myselfDao.selectBack(userFeedback);
	}

	/**
	 * 根据反馈类型id批量删除反馈信息
	 */
	@Override
	public boolean batchDelete(int[] ids) {
		boolean b = myselfDao.batchDelete(ids);
		if (!b) {
			return false;
		}
		boolean c = myselfDao.deletePhoto(ids);
		if (!c) {
			return false;
		}
		return true;
	}

	/**
	 * 后台回复反馈信息
	 */
	@Override
	public boolean replyFeedback(Integer id,String replyid, String replymessage) {
		return myselfDao.replyFeedback(id,replyid,replymessage);
	}

}
